package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingGradeDto;
import com.zzyl.entity.NursingGrade;
import com.zzyl.mapper.NursingGradeMapper;
import com.zzyl.mapper.NursingPlanMapper;
import com.zzyl.service.NursingGradeService;
import com.zzyl.vo.NursingGradeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @param
 * @return
 */
@Service
public class NursingGradeServiceImpl implements NursingGradeService {
    @Autowired
    private NursingGradeMapper nursingGradeMapper;

    @Autowired
    private NursingPlanMapper nursingPlanMapper;

    //查询所有护理等级
    @Override
    public List<NursingGradeVo> selectAllNursingGrade() {
        return nursingGradeMapper.selectAllNursingGrade();
    }

    //新增护理等级
    @Override
    public void insertNursingGrade(NursingGradeDto nursingGradeDto) {
        NursingGrade nursingGrade = BeanUtil.toBean(nursingGradeDto, NursingGrade.class);
        nursingGrade.setStatus(1);
        nursingGradeMapper.insertNursingGrade(nursingGrade);
    }


    //分页条件查询
    @Override
    public PageResponse selectByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingGradeVo> nursingGradeVos = nursingGradeMapper.selectByPage(name, status);
        PageResponse<NursingGradeVo> of = PageResponse.of(nursingGradeVos, NursingGradeVo.class);
        return of;
    }


    //查询回显
    @Override
    public NursingGradeVo selectById(Long id) {
        NursingGrade nursingGrade = nursingGradeMapper.selectById(id);
        return BeanUtil.toBean(nursingGrade, NursingGradeVo.class);
    }

    //修改
    @Override
    public void updateNursingGrade(NursingGradeDto nursingGradeDto) {
        NursingGrade nursingGrade = BeanUtil.toBean(nursingGradeDto, NursingGrade.class);
        nursingGrade.setStatus(1);
        nursingGradeMapper.updateNursingGrade(nursingGrade);
    }


    //删除
    @Override
    public void deleteNursingPlan(Long id) {
        nursingGradeMapper.deleteNursingPlan(id);
    }

    //启用/禁用
    @Override
    public void idStatusNursigGrade(Long id, Integer status) {
        nursingGradeMapper.idStatusNursigGrade(id,status);
    }
}
